package com.demo.web.modules.cin;

import com.demo.common.constant.api.base.IDEntity;
import com.demo.common.constant.api.CinBasicVOAPIConstant;
import com.demo.common.result.ResponseInfo;
import com.demo.common.result.ResultVo;
import com.demo.dao.cin.model.CinAlarmNodeVO;
import com.demo.dao.cin.model.CinDataIoNodeVO;
import com.demo.dao.cin.model.CinVariableNodeVO;
import com.demo.service.cin.CinBasicVOService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/cin/basic_vo")
public class CinBasicVOController {
    @Autowired
    private CinBasicVOService myService;

    @GetMapping("/test")
    public String test(){
        return "hello, you are in CinBasicVO test!";
    }

    //应用配置
    @RequestMapping(value = CinBasicVOAPIConstant.CIN_APPLICATION_API_LIST, method = RequestMethod.POST)
    public ResultVo getApplicationList(){
        return ResponseInfo.<Object>success(myService.getApplicationList());
    }

    //项目页面树
    @RequestMapping(value = CinBasicVOAPIConstant.CIN_PROJECT_VO_TREE, method = RequestMethod.POST)
    public ResultVo getProjectTreeVo(@RequestBody IDEntity<Long> ids){
        System.out.println(ids);
        return ResponseInfo.<Object>success(myService.getProjectVOTreeById(ids.getId()));
    }

    //变量表
    @RequestMapping(value = CinBasicVOAPIConstant.CIN_VARIABLE_DATA_API_LIST, method = RequestMethod.POST)
    public ResultVo getVariableNodeVO(@RequestBody Map<String, String> map) {
        Integer pageNum = Integer.parseInt(map.get("pageNum"));
        Integer pageSize = Integer.parseInt(map.get("pageSize"));
        System.out.println(map);
        return ResponseInfo.<PageInfo<CinVariableNodeVO>>success(myService.getVariableNodeVO(map, pageNum, pageSize));
    }

    //io表
    @RequestMapping(value = CinBasicVOAPIConstant.CIN_DATA_IO_API_LIST, method = RequestMethod.POST)
    public ResultVo getDataIoNodeVO(@RequestBody Map<String, String> map) {
        Integer pageNum = Integer.parseInt(map.get("pageNum"));
        Integer pageSize = Integer.parseInt(map.get("pageSize"));
        System.out.println(map);
        return ResponseInfo.<PageInfo<CinDataIoNodeVO>>success(myService.getDataIoNodeVO(map, pageNum, pageSize));
    }

    //报警表
    @RequestMapping(value = CinBasicVOAPIConstant.CIN_ALARM_API_LIST, method = RequestMethod.POST)
    public ResultVo getAlarmNodeVO(@RequestBody Map<String, String> map) {
        Integer pageNum = Integer.parseInt(map.get("pageNum"));
        Integer pageSize = Integer.parseInt(map.get("pageSize"));
        System.out.println(map);
        return ResponseInfo.<PageInfo<CinAlarmNodeVO>>success(myService.getAlarmNodeVO(map, pageNum, pageSize));
    }
}
